package zsy.springframework.beans.factory.support;

import zsy.springframework.beans.factory.BeansException;
import zsy.springframework.beans.factory.chouxiang.AbstractAutowireCapableBeanFactory;
import zsy.springframework.beans.factory.config.BeanDefinition;
import zsy.springframework.beans.factory.jiekou.BeanDefinitionRegistry;

import java.util.HashMap;
import java.util.Map;

public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements BeanDefinitionRegistry {

    private Map<String, BeanDefinition> beanDefinitionMap = new HashMap<>();
    @Override
    protected BeanDefinition getBeanDefiniton(String beanName) throws BeansException {
        BeanDefinition beanDefinition = beanDefinitionMap.get(beanName);
        if (beanDefinition == null) throw new BeansException("No bean named '" + beanName + "' is defined");
        return beanDefinition;
    }

    //map的put的返回值 是之前的值
    @Override
    public void registryBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        beanDefinitionMap.put(beanName, beanDefinition);
    }
}
